package com.golxen.framework.event.condition;



import com.golxen.framework.event.condition.dao.entity.ConditionInfo;
import com.golxen.framework.event.BaseEventArg;
import com.golxen.framework.event.IEventListener;
import com.golxen.framework.user.player.GamePlayer;
import com.golxen.utils.LogUtil;
import org.slf4j.Logger;
//相当于监听器封装
public abstract class BaseCondition{

    protected static final Logger logger = LogUtil.COMMON;

    protected GamePlayer player;

    /**
     * 条件完成信息
     */
    protected ConditionInfo conditionInfo;

    //当前值
    protected IUserConditionData userConditionData;

    public BaseCondition(GamePlayer player,ConditionInfo conditionInfo,IUserConditionData userConditionData) {
        this.conditionInfo = conditionInfo;
        this.player = player;
        this.userConditionData=userConditionData;
    }

    public final IUserConditionData getUserConditionData() {
        return userConditionData;
    }


    //添加触发器
    public abstract void addTrigger(GamePlayer player);

    public abstract void removeTrigger(GamePlayer player);

    public boolean isCompleted(GamePlayer player) {
        return false;
    }

    //事件处理实现（通知）
    protected abstract void changeValue(Object object);

    protected final player_EventListenerHandle handle = new player_EventListenerHandle();

    public int getConditionId() {
        return conditionInfo.getConditionId();
    }

    public int getConditionType() {
        return conditionInfo.getType();
    }

    public ConditionInfo getActivityConditionInfo() {
        return conditionInfo;
    }

    public class player_EventListenerHandle implements IEventListener {
        @Override
        public void onEvent(BaseEventArg eventArgs) {
            changeValue(eventArgs.getObject());
        }
    }
}
